<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="js/jquery.min.js" type="text/javascript"></script>
		<script src="js/layer/layer.js"></script>
		<script src="js/ConvertCalendar.js" type="text/javascript"></script>
		<style type="text/css">
			span,
			input {
				vertical-align: middle;
			}
			
			.boxTop {
				width: 96%;
				height: 48px;
				margin: auto;
				line-height: 48px;
				font-size: 18px;
				border: 1px solid grey;
				margin-top: 30px;
			}
			
			.boxTop div {
				float: left;
				text-align: center;
			}
			
			.boxTop .lastMonth {
				width: 30%;
				cursor: pointer;
				color: blue;
			}
			
			.boxTop .lastMonth:hover {
				color: red;
			}
			
			.boxTop .nowDate {
				width: 40%;
			}
			
			.boxTop .nextMonth {
				width: 30%;
				cursor: pointer;
				color: blue;
			}
			
			.boxTop .nextMonth:hover {
				color: red;
			}
			
			.boxBottom {
				width: 96%;
				margin: auto;
				text-align: center;
				border-collapse: collapse;
				line-height: 32px;
			}
			
			table,
			table tr th,
			table tr td {
				border: 1px solid grey;
				border-top: none;
				font-weight: bold;
			}
			
			table tr td {
				width: 14%;
			}
			
			.boxBottom .dLeft {
				float: left;
				height: 88px;
				width: 29%;
				border-right: 1px dashed #6E6E6E;
			}
			
			.boxBottom .dLeft .p1 {
				margin: auto;
				font-size: 15px;
				height: 40px;
				line-height: 40px;
				margin-top: 5px;
				margin-bottom: 5px;
			}
			
			.boxBottom .dLeft .p2 {
				margin: auto;
				font-size: 13px;
				height: 24px;
				line-height: 24px;
			}
			
			.boxBottom .dRight {
				float: left;
				height: 88px;
				width: 66%;
				padding: 0 2%;
				text-align: left;
				font-size: 10px;
				cursor: pointer;
				overflow: hidden;
				text-overflow: ellipsis;
				line-height: 21px;
				white-space: pre;
				color: #EB1C27;
			}
			
			.today {
				color: #fff;
				max-width: 40px;
				border-radius: 40px;
				background-color: #23C092;
			}
		</style>
		<script>
			var today; //获取当前日期
			$(function() {
				GetCreateDate(0);
			});

			function GetCreateDate(index) {
				if(index == 0) {
					today = new Date(); //获取当前日期
				} else {
					today = new Date(today.setMonth(today.getMonth() + index));
				}
				var i, k;
				var y = today.getFullYear(); //获取日期中的年份
				var m = today.getMonth(); //获取日期中的月份(需要注意的是：月份是从0开始计算，获取的值比正常月份的值少1)
				var d = today.getDate(); //获取日期中的日(方便在建立日期表格时高亮显示当天)
				var firstday = new Date(y, m, 1); //获取当月的第一天
				var dayOfWeek = firstday.getDay(); //判断第一天是星期几(返回[0-6]中的一个，0代表星期天，1代表星期一，以此类推)
				var days_per_month = new Array(31, 28 + isLeap(y), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); //创建月份数组
				var str_nums = Math.ceil((dayOfWeek + days_per_month[m]) / 7); //确定日期表格所需的行数

				var nowDateStr = '<span>' + y + '年' + (m + 1) + '月</span><input type="button" value="返回今日" style="cursor: pointer;margin-left: 8px;" onclick="GetCreateDate(0)"/>';
				$('.nowDate').html(nowDateStr);
				var html = '';
				for(i = 0; i < str_nums; i += 1) { //二维数组创建日期表格
					html += '<tr>';
					for(k = 0; k < 7; k++) {
						var idx = 7 * i + k; //为每个表格创建索引,从0开始
						var date = idx - dayOfWeek + 1; //将当月的1号与星期进行匹配
						(date <= 0 || date > days_per_month[m]) ? date = '': date = idx - dayOfWeek + 1; //索引小于等于0或者大于月份最大值就用空表格代替
						if(date == '') {
							html += '<td>' + date + '</td>';
						} else {
							var lunar = calendar.solar2lunar(y, (m + 1), date);
							html += '<td><div class="dLeft">' +
								'<p ' + (date == d && m == new Date().getMonth() && y == new Date().getFullYear() ? 'class="p1 today"' : 'class="p1"') + '>' + date + '</p>' +
								'<p class="p2">' + (lunar.IDayCn == '初一' ? lunar.IMonthCn : lunar.IDayCn) + '</p></div>' +
								'<div class="dRight" ymd="' + (y + '-' + (m + 1) + '-' + date) + '" onclick="SetContent(this)"></div></td>'; //高亮显示当天
						}
					}
					html += '</tr>';
				}
				$('#tDate').html(html);

				var startDay = y + '-' + (m + 1) + '-' + '1';
				var endDay = y + '-' + (m + 1) + '-' + days_per_month[m];
				LoadContent(startDay, endDay);
			}
			//判断当前年份是否是闰年(闰年2月份有29天，平年2月份只有28天)
			function isLeap(year) {
				return year % 4 == 0 ? (year % 100 != 0 ? 1 : (year % 400 == 0 ? 1 : 0)) : 0;
			}

			function LoadContent(startDay, endDay) {
				console.log(startDay + '--------->' + endDay);
			}

			function SetContent(obj) {
				//alert($(obj).attr('ymd'));
				layer.prompt({
					title: '活动备录',
					value: $(obj).html(),
					formType: 2
				}, function(text, index) {
					var lines = text.split("\n");
                	var flag = false;
                	for (var i = 0; i < lines.length; i++) {
                    	if (lines[i].length > 15) {
                        	flag = true;
                    	}
                	}
                	if (flag) {
                    	alert('每行文字限制15字以内！');
                    	return;
                	}
					layer.close(index);
					$(obj).html(text);
				});
			}
		</script>
	</head>

	<body>
		<div class="boxTop">
			<div class="lastMonth" onclick="GetCreateDate(-1)">
				< 上一月 
			</div>
			<div class="nowDate"></div>
			<div class="nextMonth" onclick="GetCreateDate(1)">下一月 ></div>
			</div>
			<table class="boxBottom">
				<thead>
					<tr>
						<th>周日</th>
						<th>周一</th>
						<th>周二</th>
						<th>周三</th>
						<th>周四</th>
						<th>周五</th>
						<th>周六</th>
					</tr>
				</thead>
				<tbody id="tDate">

				</tbody>
			</table>
	</body>

</html>